#include "systemconfig.h"

#include <QSettings>
#include <QGuiApplication>
#include <QFile>
#include <QTextCodec>

QSettings* SystemConfig::g_SystemConfig = nullptr;

SystemConfig::SystemConfig()
{

}

SystemConfig::~SystemConfig()
{

}

void SystemConfig::initConfig()
{
    //获取程序文件的路径
    QString path = QGuiApplication::applicationDirPath();
    QString configFile = path + "/config.ini";
    g_SystemConfig = new QSettings(configFile,QSettings::IniFormat);
    g_SystemConfig->setIniCodec(QTextCodec::codecForName("UTF-8"));

    //查看配置文件是否存在
    QFile file(configFile);
    if(!file.exists())
    {
        g_SystemConfig->setValue("server/ip","127.0.0.1");
        g_SystemConfig->setValue("server/port","12345");
        g_SystemConfig->setValue("info/flag",false);
        g_SystemConfig->setValue("rip/ripCacheSize",128*1024*1024);
        g_SystemConfig->setValue("rip/prnCacheSize",0);//1024*5 MB
        g_SystemConfig->setValue("setting/language","en");
        g_SystemConfig->setValue("setting/sizeunit","mm");
        g_SystemConfig->setValue("setting/paperwidth","330");
        g_SystemConfig->setValue("setting/ripThreads",1);
        //g_SystemConfig->setValue("setting/thickness","smooth");
        QVariantList inkSettingList;
        inkSettingList << 0 << 0 << 0 << 0 << 0 << 0;
        g_SystemConfig->setValue("wifiSetting/wifiLock",false);
        g_SystemConfig->sync();
    }
}

QVariant SystemConfig::value(const QString &key, const QVariant &defaultValue) const
{
    return g_SystemConfig->value(key,defaultValue);
}

void SystemConfig::setValue(const QString &key, const QVariant &defaultValue) const
{
    g_SystemConfig->setValue(key,defaultValue);
}



